<?php

function check_log_in() {

    global $db;

    if (!isset($_SESSION["login"])) {
        return false;
    }

    $username = mysql_real_escape_string($_SESSION["login"]["username"]);
    $email    = mysql_real_escape_string($_SESSION["login"]["email"]);
    $password = mysql_real_escape_string($_SESSION["login"]["password"]);

    $result = $db->query_first("SELECT * FROM members WHERE (username='".$username."' OR email='".$email."') AND password='".$password."' AND status='yes'");

    if ($result) {

        $_SESSION["login"]["id"] 			= intval($result["id"]);
        $_SESSION["login"]["username"] 		= $result["username"];
        $_SESSION["login"]["password"] 		= $result["password"];
        $_SESSION["login"]["email"] 		= $result["email"];

        return true;

    } else {
        return false;
    }


}

function check_login_single(){
	global $db;
	$username = mysql_real_escape_string($_SESSION['login']["username"]);
    $password = mysql_real_escape_string($_SESSION['login']["password"]);
    $result = $db->query_first("SELECT last_login FROM members WHERE (username='".$username."' OR email='".$email."') AND password='".$password."' AND status='yes'");
	if ($result["last_login"]==$_SESSION['login']["last_login"]) {
        return true;
    } else {
		unset($_SESSION["login"]);
		$_SESSION['member_already_login'] = 1;
        return false;
    }
}


/*
function check_member_login() {
    global $CONFIG_MEMBER_LINK,$params;
    $arrAccept = array($CONFIG_MEMBER_LINK['send-pass'],
            $CONFIG_MEMBER_LINK['send-confirm'],
            $CONFIG_MEMBER_LINK['change-pass-mail']
    );
    if($_SESSION['login']['id']>0 && $_SESSION["login"]["username"]!='' && $_SESSION["login"]["email"]!='' || in_array($params[1], $arrAccept)) {
        return true;
    }else {
        return false;
    }

}
 *
 */
function check_member_login() {
    global $CONFIG_MEMBER_LINK,$params;

    if($_SESSION['login']['id']>0 && $_SESSION["login"]["username"]!='' && $_SESSION["login"]["email"]!='' ) {
        return true;
    }else {
        return false;
    }

}
function obCallBackEn($buffer) {
    global $CONFIG,$arrLang;

    $buffer = str_replace("[page_title]", $CONFIG['site_title'],$buffer);
    $buffer = str_replace("[meta_keyword]", $CONFIG['site_keyword'],$buffer);
    $buffer = str_replace("[meta_description]", $CONFIG['site_desc'],$buffer);
    foreach($arrLang as $k => $v) {
        $buffer = str_replace($k, $v,$buffer);
    }

    return $buffer;
}
function obCallBackVn($buffer) {
    global $CONFIG,$arrLang;

    $buffer = str_replace("[page_title]", $CONFIG['site_title'],$buffer);
    $buffer = str_replace("[meta_keyword]", $CONFIG['site_keyword'],$buffer);
    $buffer = str_replace("[meta_description]", $CONFIG['site_desc'],$buffer);
    foreach($arrLang as $k => $v) {
        $v = str_replace('[', '',$k);
        $v = str_replace(']', '',$v);
        $buffer = str_replace($k, $v,$buffer);
    }

    return $buffer;
}

function get_news_thumb($thumb,$size='') {
    global $CONFIG;
    if($size=='') {
        return $thumb;
    }else {
        $new_thumb = str_replace($CONFIG['thumb_size_news'][0],$size,$thumb);
        if(!is_file(SITE_BASE_DIR.$new_thumb)) {
            if(!is_file(SITE_BASE_DIR.$thumb)) {
                $new_thumb = SITE_IMAGES_URL."/no-".$size.".gif";
                if(!is_file($new_thumb)) {
                    $new_thumb = SITE_IMAGES_URL."/no-110-100.gif";
                }
            }else {
                $new_thumb = $thumb;
            }
        }
        return $new_thumb;
    }
}
function get_property_thumb($thumb,$size='') {
    global $CONFIG;
    if($size=='') {
        return $thumb;
    }else {
        $new_thumb = str_replace($CONFIG['thumb_size_property'][0],$size,$thumb);
        if(!is_file(SITE_BASE_DIR.$new_thumb)) {
            if(!is_file(SITE_BASE_DIR.$thumb)) {
                $new_thumb = SITE_IMAGES_URL."/no-".$size.".gif";
                if(!is_file($new_thumb)) {
                    $new_thumb = SITE_IMAGES_URL."/no-real-110-100.gif";
                }
            }else {
                $new_thumb = $thumb;
            }
        }
        return $new_thumb;
    }

}
function get_project_thumb($thumb,$size='') {
    global $CONFIG;
    if($size=='') {
        return $thumb;
    }else {
        $new_thumb = str_replace($CONFIG['thumb_size_property'][0],$size,$thumb);
        if(!is_file(SITE_BASE_DIR.$new_thumb)) {
            if(!is_file(SITE_BASE_DIR.$thumb)) {
                $new_thumb = "/images/no-".$size.".gif";
                if(!is_file(SITE_BASE_DIR.$new_thumb)) {
                    $new_thumb = SITE_IMAGES_URL."/no-110-100.gif";
                }
            }else {
                $new_thumb = $thumb;
            }
        }
        return $new_thumb;
    }

}
function input($data_name , $type = 'request') {
    if (is_array($data_name)) {
        foreach ($data_name as $name) {
            $data[$name] = input($name , $type);
        }
        return $data;
    }
    $data = null;
    switch ($type) {
        case 'get':
            if (array_key_exists($data_name , $_GET)) $data = $_GET[$data_name];
            break;
        case 'post':
            if (array_key_exists($data_name , $_POST)) $data = $_POST[$data_name];
            break;
        case 'cookie':
            if (array_key_exists($data_name , $_COOKIE)) $data = $_COOKIE[$data_name];
            break;
        case 'request':
        default:
            if (array_key_exists($data_name , $_REQUEST)) $data = $_REQUEST[$data_name];
            break;
    }
    $data = array_trimslashes($data);
    return $data;
}

function xmlseo($data_name) {

    $data_name[count($data_name)-1] = trim(str_replace(".html","",$data_name[count($data_name)-1]));

    return $data_name;
}

function explode_param($param) {
    global $CONFIG_OPTION;

    $arr = explode('-',$param);
    $arr_new = array();
    $arr_new[0] = $arr[0];
    $arr_new[2] = end($arr);
    unset($arr[0]);
    $arr_pop = $CONFIG_OPTION;
    array_pop($arr_pop);
    if(in_array($arr_new[0],$arr_pop)) {
        array_pop($arr);
    }
    $arr_new[1] = implode('-',$arr);
    return $arr_new;
}
//function get link : $module : "property","news","faq","search"====$option : "cat" Or "detail"
function get_link($module="",$option="",$name_link="") {
    global $CONFIG_MODULE,$CONFIG_OPTION;
    $link = SITE_URL."/".$CONFIG_MODULE[$module];

    if(!empty($name_link)) {
        $name_link = "-".$name_link;
    }

    switch ($option) {
        case 'cat':
            $link = $link."/".$CONFIG_OPTION["cat"].$name_link."-1";
            break;
        case 'archive':
            $link = $link."/".$CONFIG_OPTION["archive"].$name_link."-1";
            break;
        case 'geo':
            $link = $link."/".$CONFIG_OPTION["geo"].$name_link."-1";
            break;
        case 'tags':
            $link = $link."/".$CONFIG_OPTION["tags"].$name_link."-1";
            break;
        case 'detail':
            $link = $link."/".$CONFIG_OPTION["detail"].$name_link.".html";
            break;
        default:
            if($name_link!='') {
                $link = $link."/".$option.'/'.$name_link;
            }else {
                if($option!='') {
                    $link = $link."/".$option;
                }
            }
            break;
    }
    return $link;
}
function get_link_page($module="",$option="",$name_link="") {

    global $CONFIG_MODULE,$CONFIG_OPTION;

    $link = SITE_URL."/".$CONFIG_MODULE[$module];



    if(!empty($name_link)) {
        $name_link = "-".$name_link;
    }

    switch ($option) {
        case 'cat':
            $link = $link."/".$CONFIG_OPTION["cat"].$name_link;
            break;
        case 'tags':
            $link = $link."/".$CONFIG_OPTION["tags"].$name_link;
            break;
        case 'archive':
            $link = $link."/".$CONFIG_OPTION["archive"].$name_link;
            break;
        case 'geo':
            $link = $link."/".$CONFIG_OPTION["geo"].$name_link;
            break;
        case 'detail':
            $link = $link."/".$CONFIG_OPTION["detail"].$name_link.".html";
            break;
        default:
            if($name_link!='') {
                $link = $link."/".$option.'/'.$name_link;
            }else {
                $link = $link."/".$option;
            }
            break;
    }

    return $link;

}
function sum_str($str,$lenght) {
    if(strlen($str)>$lenght) {
        return substr($str,0,$lenght)."...";
    }

    return $str;
}
// trim slashes
function trimslashes($text,$fore=false) {
    if (get_magic_quotes_gpc() || $fore) $text = stripslashes($text);
    return $text;
}

// array trim slashes
function array_trimslashes($arr,$fore=false) {
    if (is_array($arr)) {
        foreach ($arr as $key => $var) {
            $arr[$key] = array_trimslashes($var,$fore);
        }
    } else $arr = trimslashes($arr,$fore);
    return $arr;
}
//FUNCTION GET NEW MESSAGE
function get_new_message($id) {
    global $db;

    $mess = $db->query_first("SELECT COUNT(mes_id) as m FROM admin_message WHERE to_id =".intval($id)." AND `read`='No'");

    return $mess["m"];
}
//FUNCTION PAGE
function paging_small($page,$total,$url) {
    if ($total>1) {
        if($page>1) {
            $prevPage = $page-1;
        }else {
            $prevPage = 1;
        }
        if($page<$total) {
            $nextPage = $page+1;
        }else {
            $nextPage = $total;
        }

        if($page==1) {
            $strPrevPage = '<a href="javascript:void(0);"><img src="/images/pagenone_l.gif" width="22" height="21" border="0" id="pageactive_l" /></a>';
        }else {
            $strPrevPage = '<a href="'.$url.'-'.$prevPage.'"><img src="/images/pageactive_l.gif" width="22" height="21" border="0" id="pageactive_l" /></a>';
        }

        if($page==$total) {
            $strNextPage = '<a href="javascript:void(0);"><img src="/images/pagenone_r.gif" width="22" height="21" border="0" id="pageactive_r" /></a>';
        }else {
            $strNextPage = '<a href="'.$url.'-'.$nextPage.'"><img src="/images/pageactive_r.gif" width="22" height="21" border="0" id="pageactive_r" /></a>';
        }

        return $strPrevPage.$strNextPage;
    }
}

function paging_small_member($page,$total,$url) {
    if ($total>1) {
        if($page>1) {
            $prevPage = $page-1;
        }else {
            $prevPage = 1;
        }
        if($page<$total) {
            $nextPage = $page+1;
        }else {
            $nextPage = $total;
        }

        if($page==1) {
            $strPrevPage = '<a href="javascript:void(0);"><img src="/images/pagenone_l.gif" width="22" height="21" border="0" id="pageactive_l" /></a>';
        }else {
            $strPrevPage = '<a href="'.$url.'/'.$prevPage.'"><img src="/images/pageactive_l.gif" width="22" height="21" border="0" id="pageactive_l" /></a>';
        }

        if($page==$total) {
            $strNextPage = '<a href="javascript:void(0);"><img src="/images/pagenone_r.gif" width="22" height="21" border="0" id="pageactive_r" /></a>';
        }else {
            $strNextPage = '<a href="'.$url.'/'.$nextPage.'"><img src="/images/pageactive_r.gif" width="22" height="21" border="0" id="pageactive_r" /></a>';
        }

        return $strPrevPage.$strNextPage;
    }
}

function paging($page,$total,$url) {
    if ($total>1) {
        if ($page!=1) {
            $dau=$page-5;
            if ($dau<=0) {
                $dau=1;
                $dit=5-$page;
            }
            $dit=$dit+$page+5;
            if ($dit>$total) {
                $dit=$total;
                $dau=$total-10;
                if ($dau<=0) {
                    $dau=1;
                }
            }
        }
        else {
            $dau=1;
            $dit=10;
            if ($dit>$total) {
                $dit=$total;
            }
        }
        if ($page >$total) {
            $dau=1;
            $dit=1;
        }
        for ($i=$dau;$i<=$dit;$i++) {
            if ($i==$page) {

                $pages.="<li><a class='currentpage'>$i</a></li>";

            }
            else {

                $pages.="<li><a href=".$url.'-'.$i.get_string_url_search().">$i</a></li>";

            }
        }
        // get page >> <<
        //if($page <=1){$backpage = 1;}else{$backpage = $page - 1;}
        //if($page >=$total){$nextpage = $total;}else{$nextpage = $page + 1;}
        // page string
        echo "<div class='phantrang'>";
        echo '<div class="pagination1">
                <ul>';

        echo "<li><a href=".$url."-1 class='prevnext'>«</a></li>";
        echo $pages ;
        echo"<li><a href=".$url."-".$total." class='prevnext'>»</a></li>";
        echo'</ul>
              </div>
              </div>';

    //return $page_str;

    } else {
        return false;
    }
}
function get_string_url_search($arrRemoveParam=array('page','params')) {
    $strParamsGet = '';
    $arrRemoveValue = Array('TÃ¬m kiáº¿m BÄ�S','bds');
    $i=0;
    in_array($key, $arrRemoveParam);
    foreach ($_GET as $key=>$item) {
        if(!in_array($item, $arrRemoveValue)) {
            if($i==0 && !in_array($key, $arrRemoveParam)) {
                $strParamsGet .= '?'.$key.'='.$item;
            }else if($i!=0 && !in_array($key, $arrRemoveParam)) {
                    $strParamsGet .= '&'.$key.'='.$item;
                }
        }

        $i++;
    }
    return $strParamsGet;
}
function paging_member($page,$total,$url) {
    if ($total>1) {
        if ($page!=1) {
            $dau=$page-5;
            if ($dau<=0) {
                $dau=1;
                $dit=5-$page;
            }
            $dit=$dit+$page+5;
            if ($dit>$total) {
                $dit=$total;
                $dau=$total-10;
                if ($dau<=0) {
                    $dau=1;
                }
            }
        }
        else {
            $dau=1;
            $dit=10;
            if ($dit>$total) {
                $dit=$total;
            }
        }
        if ($page >$total) {
            $dau=1;
            $dit=1;
        }
        for ($i=$dau;$i<=$dit;$i++) {
            if ($i==$page) {

                $pages.="<li><a class='currentpage'>$i</a></li>";

            }
            else {

                $pages.="<li><a href=".$url."/$i>$i</a></li>";

            }
        }
        // get page >> <<
        //if($page <=1){$backpage = 1;}else{$backpage = $page - 1;}
        //if($page >=$total){$nextpage = $total;}else{$nextpage = $page + 1;}
        // page string

        echo '<ul>';
        echo "<li><a href=".$url."/1 class='prevnext'>«</a></li>";
        echo $pages ;
        echo"<li><a href=".$url."/".$total." class='prevnext'>»</a></li>";
        echo'</ul>';

    //return $page_str;

    } else {
        return false;
    }
}
//FUNCTION PAGE
function paging_ajax($page,$total,$tab,$mode,$price,$id) {
    if ($total>1) {
        if ($page!=1) {
            $dau=$page-5;
            if ($dau<=0) {
                $dau=1;
                $dit=5-$page;
            }
            $dit=$dit+$page+5;
            if ($dit>$total) {
                $dit=$total;
                $dau=$total-10;
                if ($dau<=0) {
                    $dau=1;
                }
            }
        }
        else {
            $dau=1;
            $dit=10;
            if ($dit>$total) {
                $dit=$total;
            }
        }
        if ($page >$total) {
            $dau=1;
            $dit=1;
        }
        for ($i=$dau;$i<=$dit;$i++) {
            if ($i==$page) {

                $pages.="<li><a class='currentpage'>$i</a></li>";

            }
            else {

                $pages.="<li><a href='javascript:void(0);' onclick=get_property_ajax(".$tab.",".$i.",'".$mode."',$price,$id);>$i</a></li>";

            }
        }
        // get page >> <<
        //if($page <=1){$backpage = 1;}else{$backpage = $page - 1;}
        //if($page >=$total){$nextpage = $total;}else{$nextpage = $page + 1;}
        // page string
        echo "<div class='phantrang'>";
        echo '<div class="pagination1">
                <ul>';

        echo "<li><a href='javascript:void(0);' class='prevnext' onclick=get_property_ajax(".$tab.",1,'".$mode."',$price,$id);>«</a></li>";
        echo $pages ;
        echo"<li><a href='javascript:void(0);' class='prevnext' onclick=get_property_ajax(".$tab.",".$total.",'".$mode."',$price,$id);>»</a></li>";
        echo'</ul>
              </div>
              </div>';

    //return $page_str;

    } else {
        return false;
    }
}
// Get only member in a string : ilove2you3much => return only 23
function get_only_number($string, $concat = true) {
    $length = strlen($string);
    for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
        if (is_numeric($string[$i]) && $concat_flag) {
            $int .= $string[$i];
        } elseif(!$concat && $concat_flag && strlen($int) > 0) {
            $concat_flag = false;
        }
    }

    return (int) $int;
}

//tra ve trang thai check box form
function setSelectedBoxValue($postValue,$dbValue) {
    if($postValue==$dbValue) {
        return ' selected="selected" ';
    }
}

//tra ve trang thai select box form
function setCheckedBoxValue($postValue,$dbValue,$default=false) {
    if($postValue==$dbValue) {
        echo 'checked="checked"';
    }else if($default) {
            echo ' checked="checked" ';
        }
}
//Lay chuoi duong dan trang
function get_string_url($arrRemoveParam=array('page')) {
    $strParamsGet = '?';
    $i=0;
    in_array($key, $arrRemoveParam);
    foreach ($_GET as $key=>$item) {
        if($i==0 && !in_array($key, $arrRemoveParam)) {
            $strParamsGet .= $key.'='.$item;
        }else if($i!=0 && !in_array($key, $arrRemoveParam)) {
                $strParamsGet .= '&'.$key.'='.$item;
            }
        $i++;
    }
    return $_SERVER['PHP_SELF'].$strParamsGet;
}
//=============================================================

function print_gzipped_page() {

    global $HTTP_ACCEPT_ENCODING;
    if( headers_sent() ) {
        $encoding = false;
    }elseif( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ) {
        $encoding = 'x-gzip';
    }elseif( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ) {
        $encoding = 'gzip';
    }else {
        $encoding = false;
    }

    if( $encoding ) {
        $contents = ob_get_contents();
        ob_end_clean();
        header('Content-Encoding: '.$encoding);
        print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
        $size = strlen($contents);
        $contents = gzcompress($contents, 9);
        $contents = substr($contents, 0, $size);
        print($contents);
        exit();
    }else {
        ob_end_flush();
        exit();
    }
}

function set_page_title_meta($title='',$keyword='',$description='') {
    global $CONFIG;
    if($title!='') {
        $CONFIG['site_title']			= $title;
    }
    if($keyword!='') {
        $CONFIG['site_keyword']			= $keyword;
    }
    if($$description!='') {
        $CONFIG['site_desc']			= $description;
    }
}
//cat chuoi theo tu
function cutString($str, $len) {
	$arrWord = explode(' ', $str);
    if(count($arrWord)>$length+1) {
        return implode(' ', array_slice($arrWord, 0, $length)).' ...';
    }else {
        return implode(' ', array_slice($arrWord, 0, $length));
    }
/*
    $last_space = mb_strrpos($temp,' ');
    if(mb_strlen($str) > $len) {
        $temp = mb_substr($str, 0, $len);
        $last_space = mb_strrpos($temp,' ');
        $temp = mb_substr($temp, 0, $last_space).' ...';
        return $temp;
    } else {
        return $str;
        ;
    }
*/
}
//Gen 1 string random : 6 characters or more....
function rand_str($length = 6, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890') {
// Length of character list
    $chars_length = (strlen($chars) - 1);

    // Start our string
    $string = $chars{rand(0, $chars_length)};

    // Generate random string
    for ($i = 1; $i < $length; $i = strlen($string)) {
    // Grab a random character from our list
        $r = $chars{rand(0, $chars_length)};

        // Make sure the same two characters don't appear next to each other
        if ($r != $string{$i - 1}) $string .=  $r;
    }

    // Return the string
    return $string;
}
function send_mail($to,$from,$from_name,$subject,$content) {
    global $db,$CONFIG;

    include SITE_BASE_DIR."/sendmail/class.phpmailer.php";

    $smtp=$db->query_first("SELECT * FROM smtp WHERE 1 ORDER BY RAND() LIMIT 0,1");

    $cfg['smtp_host']=$smtp['host'];
    $cfg['smtp_user']=$smtp['user'];
    $cfg['smtp_pass']=$smtp['pass'];

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SetLanguage("vn", "");
    $mail->Host     = $cfg['smtp_host'];
    $mail->SMTPAuth = true;
    $mail->Username = $cfg['smtp_user'];
    $mail->Password = $cfg['smtp_pass'];
    $mail->From     = $from;
    $mail->FromName = $from_name;
    $mail->AddAddress($to);
    $mail->AddReplyTo($from,$from_name);
    $mail->IsHTML(true);
    $mail->Subject  =  $subject;

    $mail->Body		=  $content;
    if($mail->Send()) {

        $db->query("UPDATE smtp SET `count`=`count`+1 WHERE id=".$smtp['id']);

        return true;

    }

    return false;
}

//Lay chuoi duong dan trang
function get_string_url_no_page() {
    global $params;

    $arrtemp = $params;
    $url = SITE_URL;
    if(count($arrtemp)>2) {
        array_pop($arrtemp);
    }
    $url = $url."/".implode('/',$arrtemp);
    return $url;
}
function show_success($mess) {
    ?>
<div class="title_dangky_tc">
    <div class="icon_reg"><span></span></div>
    <div class="title_reg">Thông báo</div>
</div>
<div class="content_tc">
    <img src="/images/thanhcong.gif" /><br /><br />
        <?=$mess?>
</div>
<?php
}

//count left in module member
function countProperty($status) {
    global $db;
    $rs = $db->query_first("SELECT count(id) as num_rows FROM property WHERE 1 AND status='$status' AND lang='".$_SESSION["lang"]."' AND  member_id = ".$_SESSION['login']['id']);
    return $rs['num_rows'];
}
function countFavouriteProperty() {
    global $db;
    $user_id = intval($_SESSION["login"]["id"]);
    $total = $db->query_first("SELECT COUNT(p.id) as num_row FROM property p LEFT JOIN favourite_property fp ON p.id=fp.pid  WHERE  uid=".$user_id." AND p.lang='".$_SESSION["lang"]."'");
    return $total['num_row'];
}



function showData($value) {
    if(trim($value)==''||$value=='0') {
        return '-';
    }else {
        return $value;
    }
}
//Function checklogin return true or false


function show_error() {

    global $CONFIG;

    if(!empty($CONFIG['error_message'])) {

        echo '<div class="form_error">
    <ul>
        <li class="class1"><b>Thông báo lỗi:</b></li>
        '.$CONFIG['error_message'].'
    </ul>
</div>';
    }
}



//=============================================================

function limitWord($str, $length) {
    $arrWord = explode(' ', $str);
    if(count($arrWord)>$length+1) {
        return implode(' ', array_slice($arrWord, 0, $length)).' ...';
    }else {
        return implode(' ', array_slice($arrWord, 0, $length));
    }
}
function format_thousand($num) {
    $count_num = strlen($num);
    if($count_num>3) {
        $str1 = substr($num,0,$count_num-3);
        $str2 = substr($num,$count_num-3,$count_num);
        $num = $str1 .".".$str2;
    }
    return $num;
}
function listAllPropertyCategoryLeft($parent_id=0) {
    global $db;
    $trees = array();

    $rsCat = $db->query("SELECT cat_id,cat_title,cat_link,create_date FROM cat_property WHERE cat_active='yes' AND cat_parent=$parent_id AND lang='".$_SESSION["lang"]."' ORDER BY cat_order");
    while($rs=$db->fetch_array($rsCat)) {
        $trees[] = array("cat_id"=>$rs['cat_id'],"cat_title"=>$rs['cat_title'],"cat_link"=>$rs['cat_link'],"create_date"=>$rs['create_date']);
    }
    return $trees;
}
function get_price_string($num) {

    $count_num = strlen($num);
    if($count_num>3) {
        $value = $num/1000;
        $value = $value." Tỷ";
        return $value;
    }

    return format_thousand($num)." Triệu ";
}
function getNewsCategory() {
    global $db;

    $rsCat = $db->query("SELECT cat_id,cat_title,cat_link,create_date FROM cat_news WHERE cat_active='yes' AND lang='".$_SESSION["lang"]."'  ORDER BY cat_order");

    return $rsCat;
}
function getIntroHeader() {
    global $db;

    $rsIntro = $db->query("SELECT title,title_link,content FROM introduce WHERE lang='".$_SESSION["lang"]."' ORDER BY id");

    return $rsIntro;
}

function getAdvClient($module,$position,$limit=10) {
    global $db;
    $sql = "SELECT * FROM adv WHERE 1 AND module LIKE '%$module%' AND  position='$position' ORDER BY create_date DESC LIMIT $limit";
    return  $db->query($sql);
}

function getPartnerClient($limit=10) {
    global $db;
    $sql = "SELECT * FROM partner WHERE 1 ORDER BY create_date DESC LIMIT $limit";
    return  $db->query($sql);
}

?>